<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <title>交易所管理</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
<blockquote class="layui-elem-quote">
    <div class="demoTable">
        <div class="layui-inline searcheBottom">
            交易所名称：
            <div class="layui-inline">
                <input id="exchangeName" class="layui-input" name="exchangeName" autocomplete="off" placeholder="交易所名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            排名：
            <div class="layui-inline">
                <select  id="rankTenFlag" name="rankTenFlag" class="layui-input" style="padding: 0px 20px;">
                    <option value="">全部</option>
                    <option value="1">前10名</option>
                </select>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            状态：
            <div class="layui-inline">
                <select  id="enableFlag" name="enableFlag" class="layui-input" style="padding: 0px 20px;">
                   <option value="">全部</option>
                    <option value="1">使用中</option>
                    <option value="0">已下架</option>
                </select>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            <a class="layui-btn" data-type="reload" id="search">搜索</a>
            <a class="layui-btn layui-btn-primary" id="reset">重置</a>
            <a data-opt="add" href="/manage/exchange/exchangeInfoAdd" id="exchangeadd" class="layui-btn"><i class="layui-icon">&#xe608;</i>新增交易所</a>
        </div>
    </div>
</blockquote>
<span style="font-size: 16px;"><b>交易所列表</b></span>
<table class="layui-hide" id="exchangeTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;

        //表格渲染
        table.render({
            elem:"#exchangeTable",
            url:"/manage/exchange/listExchange",
            method:"post",
            cols:[[
                {field:'id', title: 'ID', sort: true,align:'center'},
                {field:'exchangeName', title: '交易所名称',align:'center'},
/*                {field:'exchangeAliasName', title: '交易所别名',align:'center'},
                {field:'officialWebsiteAddres', title: '官网地址',align:'center'},
                {field:'countryName', title: '所在地',align:'center'},*/
                {field:'index', title: '指数',align:'center', sort: true},
                {field:'enableFlag', title: '状态',align:'center',
                    templet: function(d){
                        if(d.enableFlag==true){
                            return '<div class="layui-btn layui-bg-green layui-btn-xs">使用中</div>'
                        } else{
                            return '<div class="layui-btn layui-bg-gray layui-btn-xs">已下架</div>'
                        }
                    }
                },
                {field:'klineStatus', title: 'K线状态',align:'center',
                    templet: function(d){
                        if(d.klineStatus==true){
                            return '<div class="layui-btn layui-bg-green layui-btn-xs">启用</div>'
                        } else{
                            return '<div class="layui-btn layui-bg-gray layui-btn-xs">停用</div>'
                        }
                    }
                },

                {field:'updateTime', title: '修改时间', sort: true,align:'center',
                    templet: function(d){
                        if(d.updateTime !=null){
                            return util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss');
                        }else {
                            return '';
                        }
                    }
                },
                {field: 'tool', title:"操作",align:'left',align:'center',width:330,
                    templet:function(d){
                        var tool = '<a href="#" class="layui-btn layui-btn-xs" lay-event="detils">查看交易对</a>';
                        tool += '<a href="#" class="layui-btn layui-btn-xs" lay-event="elat">时间维度</a>';
                        tool += '<a href="#" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                        if(d.enableFlag==true){
                            tool+='<a href="#" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="enable">下架</a>';
                        }else{
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable">上架</a>';
                        }
//                        tool+='<a href="#" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        return tool;
                    }
                }
            ]],
            limits:[10,15,20,25,30],
            limit:10,
            page:true
        });

        //表格重载
        var active = {
            reload: function () {
                var exchangeName = $('#exchangeName');
                var rankTenFlag = $('#rankTenFlag');
                var enableFlag = $('#enableFlag');
                table.reload('exchangeTable', {
                    where: {
                        exchangeName: exchangeName.val(),
                        rankTenFlag:rankTenFlag.val(),
                        enableFlag:enableFlag.val(),
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //重置
        $("#reset").on("click",function(){
            exchangeName.value = '';
            rankTenFlag.value = '';
            enableFlag.value = '';
        });

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "enable") {
            	 layer.confirm('确定提交么', function(index){
         	        //向服务端发送删除指令
         	         $.ajax({
                    url:"/manage/exchange/exchangeEnable",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id,"enableFlag":data.enableFlag},
                    success:function(resData){
                    	layer.alert(resData.msg, {
    	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
    	          		    ,closeBtn: 1    // 是否显示关闭按钮
    	          		    ,anim: 1 //动画类型
    	          		    ,btn: ['确定'] //按钮
    	          		    ,icon: 1    // icon
    	          		    ,yes:function(){
    	          		    	if (resData.code >= 0) {
                                    layer.closeAll();
                                    table.reload('exchangeTable');
    	          	              }
    	          		    }});
                    }
                })
         	      return false;
         	      });
               
            } else if (obj.event == "edit") {
                location.href="/manage/exchange/exchangeInfoEdit?id="+data.id;
            } else if (obj.event == "del") {
                layer.confirm('确定删除么', {icon: 7, title:'提示'},function (index) {
                    $.ajax({
                            url: "/manage/exchange/deleteExchange",
                            type: "post",
                            data: { "id": data.id},
                            dataType: "json",
                            success: function (resData) {
                            	layer.alert(resData.msg, {
            	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
            	          		    ,closeBtn: 1    // 是否显示关闭按钮
            	          		    ,anim: 1 //动画类型
            	          		    ,btn: ['确定'] //按钮
            	          		    ,icon: 1    // icon
            	          		    ,yes:function(){
            	          		    	if (resData.code >= 0) {
                                            layer.closeAll();
                                            table.reload('exchangeTable');
            	          	              }
            	          		    }});
                            }
                        });
                });
            }else if(obj.event == 'detils'){
                location.href="/manage/extrading/ecList?id="+data.id +"&exchangeName="+data.exchangeName;
            }else if(obj.event == 'elat'){
                location.href="/manage/latmdle/latmdlelist?id="+data.id +"&exchangeName="+data.exchangeName;
            }
        });


    });
</script>

</body>
</html>